
import ProTable from '@ant-design/pro-table';
import type { ProColumns } from '@ant-design/pro-table';
import { Modal } from 'antd';
import React, { useState } from 'react';
import {Dealer} from '../../model';
import request from '@/utils/request';

export type FormValueType = {
    target?: string;
    template?: string;
    type?: string;
    time?: string;
    frequency?: string;
  } & Partial<Dealer>;

  
export type ChooseProps = {
    onCancel: (flag?: boolean, formVals?: FormValueType) => void;
    onSubmit: (values: Dealer[]) => Promise<void>;
    modalVisible: boolean;
    cust:number;
    volumeType:number;
  };

  
const AccountDialog: React.FC<ChooseProps> = (props)=>{

  const [selectedRowsState, setSelectedRows] = useState<Dealer[]>([]);
  const rowSelection = {
    onChange: (key:any, selectedRows:Dealer[]) => {
      setSelectedRows(selectedRows);
    }
  };

    async function dealerListData(params: any) {
      params.volumeType = props.volumeType
      params.customerType = props.cust
      var data =  request('/xwyl/volume/optionLists', {
        params,
      });
      return data;
    }

    const columns: ProColumns<Dealer>[] = [
        {
          title:"购买方名称",
          dataIndex: 'hospitalName',
        },
        {
          title:"操作",
          valueType: 'option',
          render: (text, record,_, action) => [
            <a
              key="editable"
              onClick={() => {
                props.onSubmit([record]);
              }}
            >
              选择
            </a>
          ],
        },
      ];

    return (
        <Modal
        title="选择购买方"
        width={1000}
        destroyOnClose={true}
        visible={props.modalVisible}
        onCancel={()=>{
            props.onCancel();
        }}
        onOk={()=>{
            props.onCancel();
      }}
      >
        <ProTable<Dealer>
          headerTitle='购买方列表'
          toolBarRender={false}
          request={async(params, sorter, filter) => dealerListData({ ...params, sorter, filter })}
          columns={columns}
          rowKey="id"
          search={{
              filterType: 'query',
              layout: 'horizontal',
          }}
          />
      </Modal>
    );
}
export default AccountDialog;